package com.cloudcross.ssp.service.impl;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.model.Dimension;
import com.cloudcross.ssp.service.IDimensionService;


@Service
public class DimensionService implements IDimensionService{	
	@Autowired
	private GenericIBatisDao myBatisDao;

	@Override
	public boolean add(Dimension dimension) {
		myBatisDao.save("dimensionSqlMapper.addDimension", dimension);
		return true;
	}
	
	//查询满足条件的记录数
	@Override
	public int countByParams(Map<String, Object> paramMap) {
		return myBatisDao.get("dimensionSqlMapper.queryDimensionCountByAccountId", paramMap);
	}
	

	@Override
	public Dimension findById(Long id) {
		return myBatisDao.get("dimensionSqlMapper.selectDimensionById", id);
	}
	
	@Override
	public List<Dimension> findByParams(Map<String, Object> paramMap, Pager pager) {
		if(pager == null){
			return myBatisDao.getList("dimensionSqlMapper.queryDimensionByAccountId", paramMap);
		}else{
			paramMap.put("pager", pager);
			return myBatisDao.getList("dimensionSqlMapper.queryDimensionByAccountIdWithPage", paramMap);
		}
	}
	
	@Override
	public boolean deleteById(HashMap<String, Object> paraMap) {
		myBatisDao.delete("dimensionSqlMapper.deleteDimensionById", paraMap);
		return true;
	}
	
	@Override
	public boolean edit(Dimension dimension) {
		myBatisDao.save("dimensionSqlMapper.editDimension", dimension);
		return true;
	}
	
	@Override
	public boolean updateDimensionDefault(Dimension dimension){
		myBatisDao.save("dimensionSqlMapper.updateDimensionDefaultToFalse", dimension);
		myBatisDao.save("dimensionSqlMapper.updateDimensionDefaulToTrue", dimension);
		return true;
	}
	
	@Override
	public Dimension findByName(String name) {
		return myBatisDao.get("dimensionSqlMapper.selectByName", name);
	}

	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		return false;
	}


	@Override
	public HashMap<String,Object> selectDimensionIdBydefault(Long accountId) {
		return myBatisDao.get("dimensionSqlMapper.selectDimensionIdBydefault",accountId);
	}
}

		
	
